import { useState, useEffect, useContext } from 'react'
import useBusinessMap from '../../../../../../common/BusinessMap/useBusinessMap';
import DarkCard from '../../../../../../common/DarkCard';
import { Button, Descriptions, Divider, InputNumber, Radio, Space, Table } from 'antd';
import GlobalContext from '../../../../../../../utils/GlobalContext';
import { CloseOutlined } from '@ant-design/icons';
import PanelRight from '../../../../../../common/PanelRight';
import LittleTitle from '../../../../../../common/LittleTitle';
import { resourcePath } from '../../../../../../../utils/resource';
import { drawCircle } from '../../../../../../../utils/helper/mapHelper';
import CztApi from '../../../../../../../utils/apis/CztApi';
import JzzyApi from '../../../../../../../utils/apis/JzzyApi';
export default function HuodianDetail(props) {
    const [detailItem, setDetailItem] = useState();
    const map = useBusinessMap();

    const [radius, setRadius] = useState();
    const [ypType, setYpType] = useState(1);
    const [yqList, setYqList] = useState();
    const [yxList, setYxList] = useState();
    const [params, setParams] = useState({
        pagestart: 1,
        pagesize: 5
    });

    useEffect(() => {
        if (ypType && map && radius) {
            const center = map.getView().getCenter();
            const circle = drawCircle(map, center, radius);
            if (ypType === 1) {
                CztApi.listByPolygon(circle).then(resp => {
                    setYxList(resp.data)
                })
            } else {
                JzzyApi.listByPolygon(circle).then(resp => {
                    setYxList(resp.data)
                })
            }
        }
    }, [ypType, map, radius])

    useEffect(() => {
        if (map) {
            const handler = evt => {
                const features = map.getFeaturesAtPixel(evt.pixel)
                if (features?.[0]) {
                    setDetailItem(features?.[0]?.getProperties())
                }
            }
            map.on('singleclick', handler);
            return () => {
                map.un('singleclick', handler);
            }
        }
    }, [map])

    return detailItem ? <PanelRight>
        <div style={{
            
            // border: '1px solid rgba(9,107,225,0.8)',
            pointerEvents: 'auto',
            overflow: "auto",
            borderRadius: 8
        }} className="layout-v">
            <div style={{
                fontSize: 20,
                fontWeight: "bold",
                marginBottom: 12
            }} className='layout-h center'>
                <div className='fill w0'>
                    <div style={{
                        background: `url(${resourcePath.blockTitleBg})`,
                        height: 36,
                        backgroundSize: '100% 100%',
                        fontSize: 18,
                        lineHeight: '36px',
                        paddingLeft: 12,
                        fontWeight: "bold"
                    }}>
                        火点详情
                    </div>
                </div>
                <div>
                    <Button size="small" icon={<CloseOutlined />} style={{
                        // color: "#fff"
                        background: "#00000000"
                    }} onClick={e => {
                        setDetailItem(null)
                    }} />
                </div>
            </div>
            <div className='fill layout-v '>
                <div className='layout-v'>
                    <LittleTitle >基本信息</LittleTitle>
                    <div className='fill h0' style={{
                        padding: 12
                    }}>
                        <Descriptions bordered column={1} size="middle">
                            <Descriptions.Item label="火点地址">翠屏区凤凰山</Descriptions.Item>
                            <Descriptions.Item label="预警时间">2023-07-08 14:12</Descriptions.Item>
                        </Descriptions>

                    </div>
                </div>
                <div className='fill layout-v'>
                    <LittleTitle >
                        <div className='layout-h center' style={{
                            justifyContent: "space-between",
                            paddingRight: 8
                        }}>
                            <div>研判分析</div>
                            <div>
                                <Radio.Group size="small" value={ypType} onChange={e => {
                                    setYpType(e.target.value)
                                }} buttonStyle="solid">
                                    <Radio.Button value={1}>影响范围</Radio.Button>
                                    <Radio.Button value={2}>救援保障</Radio.Button>
                                </Radio.Group>
                            </div>
                        </div>
                    </LittleTitle>
                    <div className='fill h0 layout-v' style={{
                        padding: 12
                    }}>
                        <Space>
                            <Radio.Group size='small' value={radius} onChange={e => {
                                setRadius(e.target.value)
                            }} buttonStyle="solid">
                                <Radio.Button value={5}>5km</Radio.Button>
                                <Radio.Button value={10}>10km</Radio.Button>
                                <Radio.Button value={15}>15km</Radio.Button>
                                <Radio.Button value={20}>20km</Radio.Button>
                            </Radio.Group>

                            <InputNumber size='small' placeholder='其它数值' addonAfter={"km"} style={{
                                width: 120
                            }} onChange={value => {
                                setRadius(value)
                            }} />
                        </Space>
                        <div className='fill' style={{
                            paddingTop: 12
                        }}>

                            <Table size={"small"} bordered columns={[{
                                title: '影响机构',
                                dataIndex: 'name'
                            }, {
                                title: '影响数量',
                                dataIndex: 'count',
                                align: "right",
                                render: (text) => {
                                    return text + '处'
                                }
                            }, {
                                render: (text, record) => {
                                    return <Button type="link" size="small" style={{
                                        padding: 0
                                    }}>详情</Button>
                                }
                            }]}
                                showHeader={false}
                                dataSource={yxList} />
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </PanelRight> : null;
}